package com.wnhz.work.yz.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.wnhz.work.yz.R;
import com.wnhz.work.yz.activity.PlayVideoActivity;
import com.wnhz.work.yz.bean.BrandBean;

import org.xutils.x;

import java.util.List;

/**
 * Created by admin on 2016/12/6.
 */
public class BrandAdapter extends BaseAdapter {
    private Context context;
    private List<BrandBean.InfoEntity> list;

    public BrandAdapter(Context context, List<BrandBean.InfoEntity> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        BrandViewHolder viewHolder = new BrandViewHolder();
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.brand_item, null);
            viewHolder.iv_img = (ImageView) convertView.findViewById(R.id.iv_img);
            viewHolder.rl_type = (RelativeLayout) convertView.findViewById(R.id.rl_type);
            viewHolder.tv_title = (TextView) convertView.findViewById(R.id.tv_title);
            viewHolder.tv_content = (TextView) convertView.findViewById(R.id.tv_content);

            convertView.setTag(viewHolder);
        } else {
            viewHolder = (BrandViewHolder) convertView.getTag();
        }
        x.image().bind(viewHolder.iv_img, list.get(position).getImg());
        viewHolder.tv_title.setText(list.get(position).getTitle());
        viewHolder.tv_content.setText(list.get(position).getDescribe());

        // if ("1".equals(list.get(position).getType())) {
        //    viewHolder.rl_type.setVisibility(View.GONE);
        //} else {
        viewHolder.rl_type.setVisibility(View.VISIBLE);
        viewHolder.rl_type.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, PlayVideoActivity.class);
                intent.putExtra("videoUrl", list.get(position).getUrl());
                intent.putExtra("img", list.get(position).getImg());
                intent.putExtra("title", list.get(position).getTitle());
                intent.putExtra("des", list.get(position).getDescribe());

                context.startActivity(intent);
            }
        });
        //  }

        return convertView;
    }

    class BrandViewHolder {
        ImageView iv_img;
        RelativeLayout rl_type;
        TextView tv_title;
        TextView tv_content;
    }
}
